package jflowmap.model.ontology;

import jflowmap.data.ViewConfig;
import jflowmap.model.map.GeoMap;
import jflowmap.views.AbstractView;

public class ViewDefinition {

	private final Context context;
	
	private AbstractView abstractView;
	private View view;
	private String viewName; 
	private ViewTypes viewType;
	
	ViewDefinition (final Context context) {
		this.context = context;
		this.view = new View(this.context);
	}	
	
	public ViewDefinition with (final String name, final DimensionCollection dimensions) {
		System.out.println(name + " === " + dimensions.get());
		System.out.println(name + " === " + dimensions.get());
		view.setDimensions(name, dimensions);
		return this;
	}
	
	public ViewDefinition named (final String viewName) {
		this.viewName = viewName;
		return this;
	}
	
	public ViewDefinition as (final String type) {
		this.viewType = ViewTypes.valueOf(type);
		return this;
	}

	public AbstractView getView(final ViewConfig viewConfig, GeoMap areaMap) throws Exception {
		if (this.abstractView == null) {
			this.abstractView = viewType.create(this.getName(), viewConfig, areaMap);
			this.view.setAbstractView(this.abstractView);
			this.abstractView.setView(this.view);
			this.view.constrainForView();
		}
		
		return this.abstractView;
	}
	
	public String getName() {
		return this.viewName;
	}

	public Context getContext() {
		return this.context;
	}
}
